﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using Samurai.Wakizashi.Workflow;

namespace Samurai.Workflow.Tests
{
    [TestClass]
    public class Workflow_Step
    {
        private bool _eventRaised;
        private bool _failedEventRaised;

        [TestMethod]
        public void Raises_event_when_step_is_completed()
        {
            var step = new TestWorkflowStep();
            step.Completed += Step_Completed;

            step.ExecuteStep();

            Assert.IsTrue(_eventRaised);
        }

        [TestMethod]
        public void Raises_event_when_step_has_failed()
        {
            var step = new FailedWorkflowStep();
            step.Failed += Step_Failed;

            step.ExecuteStep();

            Assert.IsTrue(_failedEventRaised);
        }

        private void Step_Completed(object sender, WorkflowStepCompletedEventArgs<TestWorkflowContext> e)
        {
            _eventRaised = true;
        }

        private void Step_Failed(object sender, WorkflowStepCompletedEventArgs<TestWorkflowContext> e)
        {
            _failedEventRaised = true;
        }
    }

    internal class TestWorkflowStep : WorkflowStepBase<TestWorkflowContext>
    {
        #region Overrides of WorkflowStepBase<TestWorkflowContext>

        /// <summary>
        /// Executes the step.
        /// </summary>
        public override void ExecuteStep()
        {
            NotifyStepCompleted();
        }

        #endregion
    }

    internal class TestWorkflowContext : IWorkflowContext
    {
        public string Value1 { get; set; }

        public int Value2 { get; set; }
    }
}
